package com.example.myyunpan.exception;

import com.example.myyunpan.entity.enums.ResponseCodeEnum;
import com.example.myyunpan.entity.vo.ResponseVO;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    @ResponseBody
    public ResponseVO<Object> handleBusinessException(BusinessException e){
        ResponseVO<Object> responseVO = new ResponseVO<>();
        responseVO.setCode(e.getCode());
        responseVO.setInfo(e.getMessage());
        responseVO.setStatus("error");
        responseVO.setData(e.getCodeEnum());
        return responseVO;
    }

//    @ExceptionHandler(Exception.class)
//    @ResponseBody
//    public ResponseVO<Object> handleException(Exception ex) {
//        ResponseVO<Object> responseVO = new ResponseVO<>();
//        responseVO.setCode(ResponseCodeEnum.CODE_500.getCode());
//        responseVO.setInfo(ex.getMessage());
//        responseVO.setStatus("error");
//        responseVO.setData(ResponseCodeEnum.CODE_500);
//        return responseVO;
//    }

}
